// pages/follow/addcostumer/add.js
const net = require("../../../utils/net.js");
const util = require("../../../utils/util.js");
const gd = getApp().globalData;
var posting =false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:[
      "接通",
      "未接通"
    ],
    starttime:"",
    type:2,
    follow_up_type:1,
    time:"",
    phone_status:1,
    textareaw:100,
    member_id:0,
    mark:"",
    tipno: 0,
    tipmsg: "",
    member_type:0,
    dest:""
  },
  getdate(){
    var dt = new Date();
    var mon = dt.getMonth()+1;
    var day = dt.getDate();
    mon = mon < 9 ? "0" + mon : mon;
    day = day < 9 ? "0" + day : day;
    return dt.getFullYear() + "-" + mon+"-"+day;
  },
  dateChange(e){
    this.setData({
      time: e.detail.value
    })
  },
  statusChange(e){ 
    this.setData({
      phone_status: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var res = wx.getSystemInfoSync();
    var member_id = options.id
    var member_type = options.type
    var that= this;
    var title = "添加预约";
    var type= 2;//2预约 1跟进
    if(member_type==1){
      title = "添加跟进";
      type = 1;
    }else{
      type = 2;
    }
    wx.setNavigationBarTitle({
      title: title,
    })
    this.setData({
      type: type,
      member_type: member_type,
      member_id: member_id,
      textareaw:res.windowWidth-110,
      time:that.getdate(),
      starttime: that.getdate()
    })
    console.log(res);
  },
  resultChange(e) {
    this.setData({
      type: e.currentTarget.dataset.val
    })
  },
  telChange(e){
    this.setData({
      follow_up_type: e.currentTarget.dataset.val
    })
  },
  input(e){
    var value = e.detail.value + "";
    var key = e.currentTarget.id + "";
    this.setData({
      [key]: value,
    });
  },
  save(){
    if(posting)return;
    posting = true;
    var that = this;
    var td = that.data;
    wx.showLoading({})
    net.request({
      url:'/GuestFollowUpPost',
      data:{
        member_ship_id:gd.id,
        member_id: td.member_id,
        shop_id:gd.shop_id,
        follow_up_type: td.follow_up_type,
        phone_status: td.phone_status*1+1,
        type: td.type,
        order_time: td.time,
        remarks:td.mark,
        remarks1: td.dest
      },success(res){
        var dt = res.data;
        if(dt.flag){
          console.log(dt);
          that.showtip(3, dt.msg);
          wx.setStorageSync("followdatachange",true);
          wx.setStorageSync("managerdatachange", true);
          // if (that.data.type==2){
          //   let obj = wx.getStorageSync("FollowUpObj");
          //   if (that.data.member_type==1){
          //     obj.mc_sell_followup_today = obj.mc_sell_followup_today * 1 + 1;
          //   }else{
          //     obj.mc_sell_followup_today = obj.mc_sell_followup_today * 1 + 1;
          //   }
            
          //   wx.setStorageSync("FollowUpObj", obj);
          // }
           wx.navigateBack({})
        }else{
          that.showtip(1, dt.msg);
        }
      },complete(){
        wx.hideLoading();
        posting = false;
      }
    })
  },
  showtip(lv, msg) {
    this.setData({
      tipno: lv,
      tipmsg: msg
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})